using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WroxControls 
{
   public class CompositeTableControl : Control 
   {
      Table _table;  // Make table a member so we can access it at any point
 
      protected override void CreateChildControls()
      {
         LiteralControl text;

         text = new LiteralControl(
                      "<h1>ASP.NET Control Development in C#</h1>");
         Controls.Add(text);

         TableRow row;
         TableCell cell;

         // Create a table and set a 2 pixel border

         _table = new Table();
         _table.BorderWidth = 2;

         Controls.Add(_table);

         // Add 10 row each with 5 cells 

         for(int x = 0; x < 10; x++) {
            // Create a row and add it to the table
         
            row = new TableRow();
            _table.Rows.Add(row);

            // Create a cell that contains the text

            for(int y = 0; y < 5; y++) {

               text = new LiteralControl("Row: " + x + " Cell: " + y);

               cell = new TableCell();
               cell.Controls.Add(text);

               row.Cells.Add(cell);
               }
           }
       }
   }
};

